package com.example.kaiya;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SubActivity extends MainActivity implements M{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub_menu);
		TextView txv = (TextView) findViewById(R.id.TextView01);		
		txv.setText(txv.getText() + " > " + M.m.getCate(M.m.picket).getSubName());
		ListView menuList = (ListView) findViewById(R.id.ListView_Sub_Menu);

		final String[] menu_show = M.m.getCate(M.m.picket).getList();
		ArrayAdapter<String> adapt =
				new ArrayAdapter<String>(this, R.layout.sub_menu_item, menu_show);
		
		menuList.setAdapter(adapt);
		
		menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
                // Note: if the list was built "by hand" the id could be used.
                // As-is, though, each item has the same id
                TextView textView = (TextView) itemClicked;
                String strText = textView.getText().toString();
                
                for(int j = 0; j < menu_show.length; j++){
                	if (strText.equalsIgnoreCase(menu_show[j])) {
                        // Launch the Game Activity
                		Log.d("MyTag3", menu_show[j]);
                		M.m.num = j;
                        startActivity(new Intent(SubActivity.this, DesActivity.class));
                    }
                }
            }
		});
	}
}
